/*
 * Copyright © 2017-2018 All Rights Reserved
 * 上海仰空网络科技有限公司 版权所有
 */

package org.chw.core.utils;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;

/**
 * @className ObjectMapperUtil
 * @description
 */
public class ObjectMapperUtil {
  private static ObjectMapper objectMapper;
  static {
    ObjectMapperUtil.objectMapper = new ObjectMapper();
    // 序列化的时候序列对象的所有属性
    objectMapper.setSerializationInclusion(JsonInclude.Include.ALWAYS);

    // 反序列化的时候如果多了其他属性,不抛出异常
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

    // 如果是空对象的时候,不抛异常
    objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
  }

  private ObjectMapperUtil() {}

  public static ObjectMapper getObjectMapper() {
    return ObjectMapperUtil.objectMapper;
  }

}
